package com.woniu.backparking;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.URL;

/**
 * 共享停车项目后台后端入口类
 *
 */
@SpringBootApplication
@MapperScan("com.woniu.backparking.mapper")
@EnableTransactionManagement
@EnableCaching
public class BackParkingApplication {

    public static void main(String[] args) {
//        URL urlOfClass = BackParkingApplication.class.getClassLoader().getResource("org/slf4j/spi/LocationAwareLogger.class");
//        System.out.println(urlOfClass);
        SpringApplication.run(BackParkingApplication.class, args);
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
    @Value("${spring.redis.host}")
    public String redisHost;
    @Value("${spring.redis.port}")
    public String redisPort;
    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://"+redisHost+":"+redisPort);
        System.out.println(config);
        return Redisson.create(config);
    }
}
